package o;

import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.SystemClock;
import android.util.Log;
import android.view.View;
import android.view.WindowManager.LayoutParams;
import androidx.annotation.NonNull;
import com.huawei.hmf.annotation.ApiDefine;
import com.huawei.hmf.annotation.Singleton;
import com.huawei.hwid.core.constants.HwAccountConstants;
import java.util.ArrayList;
import java.util.Iterator;
import o.dex.a;
import o.dex.c;
import o.dex.d;

@ApiDefine(uri = dez.class)
@Singleton
public class dfa implements dez {
    private dev ʼ;
    private boolean ʽ;
    private dfb ˊ;
    private long ˋ = 0;
    private String ˎ = null;
    private View ˏ;
    private ArrayList<dex> ॱ = new ArrayList();
    private int ॱॱ;
    private boolean ᐝ;

    public int ˋ(@NonNull Context context, @NonNull dex o_dex, Bundle bundle) {
        if (context == null) {
            throw new IllegalArgumentException("the Context is null");
        } else if (o_dex == null) {
            throw new IllegalArgumentException("the BuoyPageWindow is null");
        } else {
            Log.d("BuoyPageWindowLauncher", "create the window");
            if (ˎ(o_dex)) {
                o_dex.ˋ(bundle);
                this.ॱॱ = context.getResources().getConfiguration().orientation;
                LayoutParams ˎ = ˎ(context, o_dex.ॱˊ(), o_dex.ᐝॱ());
                o_dex.ˏ(ˎ);
                View ˏ = o_dex.ˏ();
                if (ˏ == null) {
                    throw new IllegalArgumentException("the onCreateView from BuoyPageWindow return null");
                }
                o_dex.ˎ(ˏ);
                int ˋ = ˋ(context, o_dex);
                if (this.ˊ == null) {
                    this.ˊ = new dfb(context, this);
                    this.ˊ.setSystemUiVisibility(ˋ);
                    if (!dfi.ˋ(context, this.ˊ, ˏ())) {
                        this.ˊ = null;
                        return 1;
                    }
                }
                this.ˊ.setSystemUiVisibility(ˋ);
                this.ˊ.setVisibility(0);
                ˏ.setSystemUiVisibility(ˋ);
                dfi.ˋ(context, ˏ, ˎ);
                if (!this.ॱ.isEmpty()) {
                    final dex o_dex2 = (dex) this.ॱ.get(this.ॱ.size() - 1);
                    if (o_dex2 != null && o_dex2.ˏॱ() == c.RESUMED) {
                        if (o_dex.ॱˊ() != d.GUIDE) {
                            new Handler(Looper.getMainLooper()).postDelayed(new Runnable(this) {
                                final /* synthetic */ dfa ˎ;

                                public void run() {
                                    this.ˎ.ˊ(o_dex2);
                                }
                            }, 300);
                        }
                        o_dex2.C_();
                    }
                }
                this.ॱ.add(o_dex);
                o_dex.B_();
                if (this.ʼ != null) {
                    this.ʼ.ˎ();
                }
                return 0;
            }
            Log.e("BuoyPageWindowLauncher", "forbidden open window in a short time");
            return 2;
        }
    }

    public void ˏ(@NonNull Context context, @NonNull dex o_dex) {
        if (context == null) {
            throw new IllegalArgumentException("the Context is null");
        } else if (o_dex == null) {
            throw new IllegalArgumentException("the BuoyPageWindow is null");
        } else if (this.ॱ.contains(o_dex)) {
            View ˊॱ = o_dex.ˊॱ();
            if (ˊॱ != null) {
                dfi.ˊ(context, ˊॱ);
            }
            Log.d("BuoyPageWindowLauncher", "destroy the window");
            o_dex.C_();
            o_dex.D_();
            this.ॱ.remove(o_dex);
            if (this.ॱ.isEmpty()) {
                if (this.ˏ != null) {
                    dfi.ˊ(context, this.ˏ);
                    this.ˏ = null;
                }
                if (this.ˊ != null) {
                    dfi.ˊ(context, this.ˊ);
                    this.ˊ = null;
                }
                if (this.ʼ != null) {
                    this.ʼ.ˊ();
                    return;
                }
                return;
            }
            dex o_dex2 = (dex) this.ॱ.get(this.ॱ.size() - 1);
            if (o_dex2 != null && o_dex2.ˏॱ() == c.STOPPED) {
                ॱ(context, o_dex2);
                o_dex2.B_();
            }
        } else {
            Log.w("BuoyPageWindowLauncher", "the BuoyPageWindow has not been added or has been closed");
        }
    }

    public void ॱ(@NonNull Context context) {
        if (context == null) {
            throw new IllegalArgumentException("the Context is null");
        }
        Iterator it = this.ॱ.iterator();
        while (it.hasNext()) {
            dex o_dex = (dex) it.next();
            View ˊॱ = o_dex.ˊॱ();
            if (ˊॱ != null) {
                dfi.ˊ(context, ˊॱ);
            }
            Log.d("BuoyPageWindowLauncher", "destroy the window");
            o_dex.C_();
            o_dex.D_();
        }
        this.ॱ.clear();
        if (this.ˏ != null) {
            dfi.ˊ(context, this.ˏ);
            this.ˏ = null;
        }
        if (this.ˊ != null) {
            dfi.ˊ(context, this.ˊ);
            this.ˊ = null;
        }
    }

    public void ˎ(@NonNull Context context) {
        if (context == null) {
            throw new IllegalArgumentException("the Context is null");
        } else if (!this.ॱ.isEmpty()) {
            if (this.ॱ.size() == 1) {
                ˏ(context);
            } else {
                ˏ(context, (dex) this.ॱ.get(this.ॱ.size() - 1));
            }
        }
    }

    public void ˎ(@NonNull Context context, @NonNull dex o_dex) {
        if (o_dex != null && o_dex.ˊॱ() != null) {
            o_dex.ˊॱ().setSystemUiVisibility(ˋ(context, o_dex));
            LayoutParams ͺ = o_dex.ͺ();
            if (ͺ != null) {
                ͺ.flags = 150995232;
                dfi.ˎ(context, o_dex.ˊॱ(), ͺ);
            }
        }
    }

    public void ˎ(dev o_dev) {
        this.ʼ = o_dev;
    }

    public void ˎ(boolean z) {
        this.ᐝ = z;
    }

    public void ˏ(boolean z) {
        this.ʽ = z;
    }

    void ˊ(@NonNull Context context) {
        if (context == null) {
            throw new IllegalArgumentException("the Context is null");
        }
        Iterator it = this.ॱ.iterator();
        while (it.hasNext()) {
            dex o_dex = (dex) it.next();
            View ˊॱ = o_dex.ˊॱ();
            if (ˊॱ != null) {
                LayoutParams ˎ = ˎ(context, o_dex.ॱˊ(), o_dex.ᐝॱ());
                LayoutParams ͺ = o_dex.ͺ();
                if (ͺ != null) {
                    ˎ.flags = ͺ.flags;
                }
                ˊॱ.setSystemUiVisibility(ˋ(context, o_dex));
                o_dex.ˏ(ˎ);
                dfi.ˎ(context, ˊॱ, ˎ);
                if (o_dex.ˏॱ() == c.RESUMED) {
                    o_dex.B_();
                }
                o_dex.ˋ();
            }
        }
        if (this.ˏ != null) {
            dfi.ˊ(context, this.ˏ);
            dfi.ˋ(context, this.ˏ, ˎ(context, d.NORMAL, a.LEFT));
        }
    }

    public void ˏ(@NonNull Context context) {
        ʻ(context);
        if (this.ʼ != null) {
            this.ʼ.ˋ();
        }
    }

    public void ॱ(@NonNull Context context, long j) {
        ʻ(context);
        new Handler().postDelayed(new 4(this), j);
    }

    public void ˋ(@NonNull Context context) {
        if (context == null) {
            throw new IllegalArgumentException("the Context is null");
        }
        dex o_dex = null;
        if (!this.ॱ.isEmpty()) {
            o_dex = (dex) this.ॱ.get(this.ॱ.size() - 1);
            if (o_dex != null && o_dex.ˏॱ() == c.STOPPED) {
                ॱ(context, o_dex);
                o_dex.B_();
            }
        }
        if (this.ˊ != null) {
            this.ˊ.setSystemUiVisibility(ˋ(context, o_dex));
            this.ˊ.setVisibility(0);
        }
        if (this.ʼ != null) {
            this.ʼ.ˎ();
        }
        if (this.ॱॱ != context.getResources().getConfiguration().orientation) {
            this.ॱॱ = context.getResources().getConfiguration().orientation;
            ˊ(context);
        }
    }

    public boolean ˋ() {
        return this.ॱ.size() <= 0;
    }

    public void ˊ(@NonNull Context context, @NonNull dex o_dex) {
        if (context == null) {
            throw new IllegalArgumentException("the Context is null");
        } else if (o_dex == null) {
            throw new IllegalArgumentException("the BuoyPageWindow is null");
        } else {
            LayoutParams layoutParams = null;
            if (o_dex.ॱˊ() == d.DOCK) {
                layoutParams = ˎ(context, d.NORMAL, o_dex.ᐝॱ());
                o_dex.ˎ(d.NORMAL);
            } else if (o_dex.ॱˊ() == d.NORMAL) {
                layoutParams = ˎ(context, d.DOCK, o_dex.ᐝॱ());
                o_dex.ˎ(d.DOCK);
            }
            o_dex.ˊॱ().setSystemUiVisibility(ˋ(context, o_dex));
            if (layoutParams != null) {
                LayoutParams ͺ = o_dex.ͺ();
                if (ͺ != null) {
                    layoutParams.flags = ͺ.flags;
                }
                o_dex.ˏ(layoutParams);
                dfi.ˎ(context, o_dex.ˊॱ(), layoutParams);
                o_dex.E_();
            }
        }
    }

    public boolean ॱ(a aVar) {
        if (!this.ॱ.isEmpty()) {
            dex o_dex = (dex) this.ॱ.get(this.ॱ.size() - 1);
            if (o_dex != null && o_dex.ˏॱ() == c.STOPPED) {
                if (o_dex.ᐝॱ() != aVar) {
                    return true;
                }
                return false;
            }
        }
        return false;
    }

    private void ʻ(@NonNull Context context) {
        if (context == null) {
            throw new IllegalArgumentException("the Context is null");
        }
        dex o_dex = this.ॱ.size() > 0 ? (dex) this.ॱ.get(this.ॱ.size() - 1) : null;
        if (o_dex != null && o_dex.ॱˊ() == d.GUIDE) {
            View ˊॱ = o_dex.ˊॱ();
            if (ˊॱ != null) {
                dfi.ˊ(context, ˊॱ);
            }
            o_dex.C_();
            o_dex.D_();
            this.ॱ.remove(o_dex);
        }
        Iterator it = this.ॱ.iterator();
        while (it.hasNext()) {
            o_dex = (dex) it.next();
            ˊ(o_dex);
            if (o_dex.ˏॱ() == c.RESUMED) {
                o_dex.C_();
            }
        }
        if (this.ˊ != null) {
            this.ˊ.setVisibility(4);
        }
        if (this.ˏ != null) {
            dfi.ˊ(context, this.ˏ);
            this.ˏ = null;
        }
    }

    private void ॱ(@NonNull Context context, @NonNull dex o_dex) {
        View ˊॱ = o_dex.ˊॱ();
        if (ˊॱ != null) {
            ˊॱ.setSystemUiVisibility(ˋ(context, o_dex));
            ˊॱ.setVisibility(0);
        }
    }

    private void ˊ(@NonNull dex o_dex) {
        final View ˊॱ = o_dex.ˊॱ();
        if (ˊॱ != null && ˊॱ.getVisibility() == 0) {
            ˊॱ.animate().translationX(o_dex.ᐝॱ() == a.LEFT ? (-ˊॱ.getX()) - ((float) ˊॱ.getMeasuredWidth()) : ˊॱ.getX() + ((float) ˊॱ.getMeasuredWidth())).setDuration((long) 200).setInterpolator(new kk()).withEndAction(new Runnable(this) {
                final /* synthetic */ dfa ˎ;

                public void run() {
                    ˊॱ.setVisibility(4);
                    ˊॱ.setTranslationX(0.0f);
                }
            });
        }
    }

    private LayoutParams ˎ(@NonNull Context context, @NonNull d dVar, @NonNull a aVar) {
        LayoutParams layoutParams;
        if (dVar == d.GUIDE) {
            layoutParams = new LayoutParams(-1, -1, 2005, 150995240, -2);
            if (this.ᐝ) {
                dfc.ˊ(layoutParams);
            }
            if (this.ʽ) {
                dfc.ˎ(layoutParams);
            }
        } else if (dVar == d.DOCK) {
            layoutParams = new LayoutParams(-2, -2, 2005, 150995240, -2);
            layoutParams.height = -2;
            layoutParams.width = dfc.ˏ(context, 88);
        } else {
            layoutParams = new LayoutParams(-2, -2, 2005, 150995240, -2);
            if (context.getResources().getConfiguration().orientation == 1) {
                layoutParams.width = (int) (((float) dfc.ˊ(context)) * 0.8f);
            } else {
                layoutParams.width = dfc.ˊ(context) / 2;
            }
            layoutParams.height = dfc.ˎ(context) - dfc.ˏ(context, 48);
        }
        if (context.getResources().getConfiguration().orientation == 1) {
            layoutParams.gravity = 48;
        } else {
            layoutParams.gravity = 17;
        }
        if (aVar == a.LEFT) {
            layoutParams.windowAnimations = des.c.ˎ;
            layoutParams.gravity |= 3;
        } else {
            layoutParams.windowAnimations = des.c.ˊ;
            layoutParams.gravity |= 5;
        }
        if (dVar != d.GUIDE) {
            layoutParams.x += dfc.ˏ(context, 8);
            if (context.getResources().getConfiguration().orientation == 1) {
                layoutParams.y += dfc.ˏ(context, 24);
            }
        }
        return layoutParams;
    }

    private LayoutParams ˏ() {
        return new LayoutParams(-1, -1, 2005, 134480128, -2);
    }

    private boolean ˎ(@NonNull dex o_dex) {
        long uptimeMillis = SystemClock.uptimeMillis();
        long j = uptimeMillis - this.ˋ;
        this.ˋ = uptimeMillis;
        if (o_dex.getClass().getSimpleName().equals(this.ˎ)) {
            Log.d("BuoyPageWindowLauncher", "check the interval for open buoy window: current:" + uptimeMillis + ",last:" + this.ˋ);
            if (j < 1000) {
                return false;
            }
            return true;
        }
        this.ˎ = o_dex.getClass().getSimpleName();
        return true;
    }

    private int ˋ(@NonNull Context context, @NonNull dex o_dex) {
        if (context == null || o_dex == null || context.getResources().getConfiguration().orientation != 2 || o_dex.ᐝॱ() != a.RIGHT) {
            return 134223623;
        }
        return HwAccountConstants.FLAG_TRANS_NAVIGATION_BAR;
    }
}
